import http from "../../untils/http"
//Login 登录
export const login = (username, password) => {
  return http.post(`/api/IMSPDA/LoginCheck`, {
    username,
    password,
  }).then(res => res.data)
}

//明细数据
export const getDetail = (submit) => {
  return http.post("/api/IMSPDA/searchpallet", { uniqueid: submit }).then(res => res.data)
}

//临时提交/领料退库提交/自主发货/领料出库/po退货/状态调整/数量调整/盘存/上架
export const InformationSubmit = (type, entryJson, orderEntryJson) => {
  return http.post(`/GenerateIMSXml.asmx/SaveForm`, {
    type,
    entryJson,
    orderEntryJson,
  }).then(res => res.data)
}
//api/IMSPDA/InstorageSaveForm 

export function PostDetail(url, submit) {
  return http({
    method: "post",
    url: url,
    data: submit,
    headers: {
      "Content-Type": "application/json",
    },
    transformRequest: [
      function (data) {
        let ret = "";
        for (let it in data) {
          ret += `"${it}":"${data[it]}"`;
        }
        return `{${ret}}`;
      },
    ],
  })
}


//单据信息po，提交单据日期，获取数据
//单据信息调拨，提交日期，获取数据
export function PostOrder(url, submit) {
  return http({
    method: "post",
    url: url,
    data: submit,
    headers: {
      "Content-Type": "application/json",
    },
    transformRequest: [
      function (data) {
        let ret = "";
        for (let it in data) {
          ret += `"${it}":"${data[it]}",`;
        }
        ret = ret.substring(0, ret.length - 1);
        return `{${ret}}`;
      },
    ],
  })
}

//调拨提交
export function PostSubmitA(url, submit) {
  return http({
    method: "post",
    url: url,
    data: submit,
    headers: {
      "Content-Type": "application/json",
    },
    transformRequest: [
      function (data) {
        let ret = "";
        let rus = ""
        ret += `{"LinkNo":"${data[0].LinkNo}","WareHouseId":"0020","WareHouseName":"0020","CreatedId":"${data[0].CreatedId}","CreatedName":"${data[0].CreatedName}","InDate":"${data[0].InDate}","Plant":"${data[0].Plant}","InventoryStatus":"${data[0].InventoryStatus}","BillType":"${data[0].BillType}","BillTypeName":"${data[0].BillTypeName}"}`
        let Ret = JSON.stringify(ret)
        data[1].map((item) => {
          rus += `{"WareHouseId":"0020","WareHouseName":"0020","ProductId":"${item.wl}","ProductionDate":"${item.sc}","SupplierId":"${item.gysdm}","ProducerId":"${item.scs}","Num":"${item.sl}","Unit":"${item.dw}","GuiGe":"${item.wlgg}","PONO":"","BaoJanNo":"","ExpDate":"${item.yx}","UniqueId":"${item.make}","SupplyBatchNO":"${item.gyspc}","BatchNO":"${item.ms}","StorehouseName":"${item.kw}","InventoryStatus":"${item.stkstatus}","Item":"${item.item}"},`
        });
        rus = rus.substring(0, rus.length - 2) + "}"; //删去最后rus外面的逗号
        let Rus = `[${rus}]`
        let Russ = JSON.stringify(Rus)
        return `{"type":"${data[2]}","entryJson":${Ret},"orderEntryJson":${Russ}}`
      },
    ],
  })
}

//po提交
export function PostOtherSubmit(url, submit) {
  return http({
    method: "post",
    url: url,
    data: submit,
    headers: {
      "Content-Type": "application/json",
    },
    transformRequest: [
      function (data) {
        let ret = "";
        let rus = ""
        ret += `{"CreatedId":"${data[0].CreatedId}","CreatedName":"${data[0].CreatedName}","InDate":"${data[0].InDate}","Plant":"${data[0].Plant}","InventoryStatus":"${data[0].InventoryStatus}","BillType":"${data[0].BillType}","BillTypeName":"${data[0].BillTypeName}","VisualCheck":"${data[0].VisualCheck}","AdvanceSendSample":"${data[0].AdvanceSendSample}","COA":"${data[0].COA}","InBulk":"${data[0].InBulk}"}`
        let Ret = JSON.stringify(ret)
        data[1].map((item) => {
          rus += `{"WareHouseId":"0020","WareHouseName":"0020","ProductId":"${item.wl}","ProductionDate":"${item.sc}","SupplierId":"${item.gysdm}","ProducerId":"${item.scs}","Num":"${item.sl}","Unit":"${item.dw}","GuiGe":"${item.wlgg}","PONO":"","BaoJanNo":"","ExpDate":"${item.yx}","UniqueId":"${item.make}","SupplyBatchNO":"${item.gyspc}","BatchNO":"${item.ms}","StorehouseName":"${item.kw}","InventoryStatus":"U"},`
        });
        rus = rus.substring(0, rus.length - 2) + "}"; //删去最后rus外面的逗号
        let Rus = `[${rus}]`
        let Russ = JSON.stringify(Rus)
        return `{"type":"${data[2]}","entryJson":${Ret},"orderEntryJson":${Russ}}`
      },
    ],
  })
}








